import fileinput
import os


def cmakelist_replace():
    cmake_filename = "../../CLionProjects/cpp/CMakeLists.txt"
    with fileinput.FileInput(cmake_filename,
                             inplace=True) as f:
        for line in f:
            if "cpp_2021" in line:
                print(line.replace("cpp_2021",
                                   "cpp"), end='')
            else:
                print(line, end='')


def h_file_replace():
    def listdir(path):
        for fname in os.listdir(path):
            yield os.path.join(path, fname)
    list_h_files = list(filter(lambda e: e.endswith('.h'), list(listdir("../../CLionProjects/cpp/"))))
    for filename in list_h_files:
        with fileinput.FileInput(filename,
                                 inplace=True) as f:
            for line in f:
                if "CPP_2021" in line:
                    print(line.replace("CPP_2021",
                                       "CPP"), end='')
                else:
                    print(line, end='')

cmakelist_replace()
h_file_replace()
